package LeetCode.leetcode232;

import java.util.Stack;

public class MyQueue2 {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public MyQueue2() {
        Stack<Integer> stack1 = new Stack<>();
        Stack<Integer> stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        //从1->2再pop
        while (!stack1.empty()) {
            stack2.push(stack1.pop());
        }
        //pop
        int res = stack2.pop();
        //从2->1
        while (!stack2.empty()) {
            stack1.push(stack2.pop());
        }
        return res;
    }

    public int peek() {
        //从1->2再pop
        while (!stack1.empty()) {
            stack2.push(stack1.pop());
        }
        //peek
        int res = stack2.peek();
        //从2->1
        while (!stack2.empty()) {
            stack1.push(stack2.pop());
        }
        return res;
    }

    public boolean empty() {
        return stack1.empty();
    }
}
